package com.zoe.onelink.mybatis.provider;

import com.zoe.onelink.util.OnelinkContextHolder;
import com.zoe.onelink.util.SpringUtil;
import com.zoe.onelink.util.StrUtil;
import lombok.RequiredArgsConstructor;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>标题: </p>
 * <p>描述: </p>
 * <p>版权: Copyright (c) 2022</p>
 * <p>公司: 智业软件股份有限公司</p>
 *
 * @version: 1.0
 * @author: ruansheng
 * @date: 2022-01-06
 */
@RequiredArgsConstructor
public class DefaultOperatorProvider implements OperatorProvider {

    private static final String OPERATOR_HEADER_NAME = "operator";

    /**
     * 获取操作人
     */
    @Override
    public String getOperator() {
        String operator = OnelinkContextHolder.getString(OPERATOR_HEADER_NAME);
        if (StrUtil.isNotBlank(operator)) {
            return operator;
        }
        HttpServletRequest request = SpringUtil.getRequest();
        if (request == null) {
            return "";
        }
        operator = request.getHeader(OPERATOR_HEADER_NAME);
        return operator == null ? "" : operator;
    }

}
